{% extends "base.html" %}
{% load post_tags %}
{% block title %}My blog{% endblock %}

{% block content %}
    {% if tag %}
        <h1>Search tags</h1>
    {% else  %}
        <h1>My blog</h1>
    {% endif %}
    <div class="module">
        {% for post in posts %}
            <div class="course-info">
                <h3>{{ post.title }}</h3>
                {#                    {{ post.body|djangomarkdown|truncatechars_html:30}}#}
                <p>
                    <a href="{% url "post_edit"  post.id %}">Edit</a>
                    <a href="{% url "post_delete"  post.id %}">Delete</a>
                    <a href="{% url "post_detail"  post.id %}">Detail</a>
                    Tags:
                    {% for tag in post.tags.all %}
                        <a href="{% url "post_list_by_tag" tag.name %}">
                            {{ tag.name }}
                        </a>
                        {% if not forloop.last %}, {% endif %}
                    {% endfor %}
                </p>
            </div>
        {% empty %}
            <p>You haven't created any courses yet.</p>
        {% endfor %}
        <div class="pagination">
    <span class="step-links">
        {% if posts.has_previous %}
            <a href="?page={{ posts.previous_page_number }}">Previous</a>
        {% endif %}
        <span class="current">
            Page {{ posts.number }} of {{ posts.paginator.num_pages }}.
        </span>
        {% if posts.has_next %}
            <a href="?page={{ posts.next_page_number }}">Next</a>
        {% endif %}
    </span>
        </div>
    </div>
{% endblock %}
{% block sidebar %}
    <form action="" method="post">
        {{ form.search }}
        {% csrf_token %}
        <input type="submit" value="Search">
    </form>
{% endblock %}
{% block sidebar_second %}
    <ul>
        {% for post in tag_lists %}
            {% for tag in post.tags.all %}
                <li style=" float:left;margin: 1px 5px;list-style:none;display:block;white-space: nowrap;width: 40%"><a href="{% url "post_list_by_tag" tag.name %}">
                    {{ tag.name }}({{forloop.counter}})
                </a></li>
                {% if not forloop.last %}, {% endif %}
            {% endfor %}
        {% endfor %}
    </ul>
{% endblock %}